package com.g2room.myuall.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 系统静态变量类
 *
 * @createTime: 2014-11-25 上午9:44:34
 * @author: <a href="mailto:gaoxvguo060@haopinfeng.com">高绪国</a>
 * @version: 0.1
 * @changesSum: 
 * 
 */
public class Constants {
	// 校园图片域名
	public static final String UnivImgUrl = "http://img.myuall.com";
	// 校园图片本地目录
	public static final String UnivImgDir = "/home/data/resource/myuall/school";
//	public static final String UnivImgDir = "E:/高绪国/资料/images/20160804/myuall/img";
	/** 类别：美图共赏。ID=8 */
	public static final Integer CAT_IMAGE_ID = 8;
	/** COOKIE中保存的省份ID，改为了保存论坛ID，值为provinceId */
	public static final String COOKIE_PROVICEID = "provinceId";
	/** COOKIE中保存的省份名称，改为了保存论坛名称，值为provinceName */
	public static final String COOKIE_PROVICENAME = "provinceName";
	/** SESSION中保留的用户登录前最后一次访问地址，值为lastUrl */
	public static final String SESSION_LASTURL = "lastUrl";
	/** SESSION中保留的用戶對象KEY值，值为user */
	public static final String SESSION_USER = "user";
	/** SESSION中保留的系统用戶對象KEY值，值为user */
	public static final String SESSION_SYS_USER = "sysuser";
	/** 每页显示数据量 */
	public static final int PAGE_SIZE = 30;
	/** 主题状态，未审核：值为0 */
	public static final int POST_UNAUDIT = 0;
	/** 主题状态，已审核：值为1 */
	public static final int POST_AUDIT = 1;
	/** 主题状态，已隐藏：值为2 */
	public static final int POST_HIDE = 2;
	/** 主题状态，已删除：值为3 */
	public static final int POST_DEL = 3;
	
	/** 主题置顶状态，不置顶即正常：值为0 */
	public static final int STICK_NORMAL = 0;
	/** 主题置顶状态，板块置顶：值为1 */
	public static final int STICK_CAT = 1;
	/** 主题置顶状态，全局置顶：值为3 */
	public static final int STICK_ALL = 3;
	
	/** 通用状态，正常：值为0 */
	public static final int STATUS_NORMAL = 0;
	/** 通用状态，不显示：值为1 */
	public static final int STATUS_HIDDEN = 1;
	
	/** 是否精华，非精华：值为0 */
	public static final int DIGEST_NO = 0;
	/** 是否精华，精华：值为1 */
	public static final int DIGEST_YES = 1;
	
	public static String Md5(String str ) {
		String resultStr = "";
		try {
			MessageDigest md = MessageDigest.getInstance("MD5"); 
			md.update(str.getBytes()); 
			byte b[] = md.digest(); 
	
			int i; 
	
			StringBuffer buf = new StringBuffer("");
			for (int offset = 0; offset < b.length; offset++) {
				i = b[offset];
				if(i<0) i+= 256;
				if(i<16)
				buf.append("0");
				buf.append(Integer.toHexString(i));
			}
			resultStr = buf.toString();//32位的加密 
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return resultStr;
	}
	
	/**
	 * 时间转换为字符串
	 *
	 * @param {Date} date	需要格式化的日期
	 * @param {String} format	格式化字符串，如yyyy-MM-dd HH:mm:ss
	 * @return
	 * @auther <a href="mailto:gaoxg@FOUNDER.COM.CN">Gao Xuguo</a>
	 * May 16, 2013 3:44:23 PM
	 */
	public static String date2String(Date date, String format) {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(date);
	}
	// 环境：1-PC；2、笔记本；3、linux
	public static int ev = 2;
	public static String basePath = "";
	public static String baseHtmlPath = "";
	public static String localImgDir = "";
	static {
		switch (ev) {
			case 1:
				basePath = "D:/workspace/code/eclipse/self/driving/src/main/webapp/temp/";
				baseHtmlPath = "E:/高绪国/资料/html/";
				localImgDir = "E:/高绪国/资料/images/";
				break;
			case 2:
				basePath = "D:/workspace/code/eclipse/gxg/driving_1/src/main/webapp/temp/";
				baseHtmlPath = "E:/高绪国/资料/html/";
				localImgDir = "E:/高绪国/资料/images/20160804/myuall/img/";
				break;
			case 3:
				basePath = "/home/data/resource/tmpl/";
				baseHtmlPath = "/home/data/resource/html/";
				localImgDir = "/home/data/resource/images/";
				break;
		}
	}
	
	public static void main(String[] args) {
		System.out.println(Md5("123456gxg"));
	}
}
